package com.example.duomeitijuhe.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.example.duomeitijuhe.R;

import java.util.ArrayList;

/**
 * Created by Michael on 2014/10/16.
 */
public class ContentPictureAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<Bitmap> pictureLists = new ArrayList<Bitmap>();


    public ContentPictureAdapter(Context context,ArrayList<Bitmap> pictureLists){
        this.context = context;
        this.pictureLists = pictureLists;
    }

        @Override
        public int getCount() {

            if (null != pictureLists) {
                return pictureLists.size();
            } else {
                return 0;
            }
        }

        @Override
        public Object getItem(int position) {

            return pictureLists.get(position);
        }

        @Override
        public long getItemId(int position) {

            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder viewHolder = null;

            if (convertView == null) {

                viewHolder = new ViewHolder();
                // 获得容器
                convertView = LayoutInflater.from(this.context).inflate(R.layout.content_picture, null);

                // 初始化组件
                viewHolder.image = (ImageView) convertView.findViewById(R.id.content_picture);
                // 给converHolder附加一个对象
                convertView.setTag(viewHolder);
            } else {
                // 取得converHolder附加的对象
                viewHolder = (ViewHolder) convertView.getTag();
            }

            // 给组件设置资源
            Bitmap bitmap = pictureLists.get(position);
            viewHolder.image.setImageBitmap(bitmap);
            return convertView;
        }
        class ViewHolder {

            public ImageView image;
        }

}
